package com.ojoin.trade.common.web.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.ojoin.trade.common.exception.DaoException;
import com.ojoin.trade.common.web.dao.UserDao;
import com.ojoin.trade.common.web.domain.Role;
import com.ojoin.trade.common.web.domain.User;

@Repository
public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao {

	public SqlSession getSqlSession() {
		return this.sqlSessionTemplate;
	}
	
	
	@Override
	public User getByLoginName(User user) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		User ret;
		try {
			ret = this.sqlSessionTemplate.selectOne(getSqlName(mapMethodName),user);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ret;
	}

	@Override
	public List<User> findUserByOfficeId(User user) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		List<User> ret;
		try {
			ret = this.sqlSessionTemplate.selectList(getSqlName(mapMethodName),user);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ret;
	}

	@Override
	public long findAllCount(User user) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		long ef;
		try {
			ef = this.sqlSessionTemplate.selectOne(getSqlName(mapMethodName),user);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ef;
	}

	@Override
	public int updatePasswordById(User user) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		int ef;
		try {
			ef = this.sqlSessionTemplate.update(getSqlName(mapMethodName),user);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ef;
	}

	@Override
	public int updateLoginInfo(User user) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		int ef;
		try {
			ef = this.sqlSessionTemplate.update(getSqlName(mapMethodName),user);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ef;
	}

	@Override
	public int deleteUserRole(User user) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		int ef;
		try {
			ef = this.sqlSessionTemplate.delete(getSqlName(mapMethodName),user);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ef;
	}

	@Override
	public int insertUserRole(User user) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		int ef;
		try {
			ef = this.sqlSessionTemplate.insert(getSqlName(mapMethodName),user);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ef;
	}

	@Override
	public int updateUserInfo(User user) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		int ef;
		try {
			ef = this.sqlSessionTemplate.update(getSqlName(mapMethodName),user);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ef;
	}
	

}
